﻿using System;
using System.Collections.Generic;

namespace ObjetoNegocio
{
    public class Busca :IObject
    {
        public DateTime Data { get; set; }
        public Usuario Usuario { get; set; }
        public List<Atributo> Atributos { get; set; }
        public decimal Codigo { get; set; }

        public override bool Equals(object obj)
        {
            if (ReferenceEquals(null, obj)) return false;
            if (ReferenceEquals(this, obj)) return true;
            if (obj.GetType() != typeof (Busca)) return false;
            return Equals((Busca) obj);
        }

        public bool Equals(Busca obj)
        {
            if (ReferenceEquals(null, obj)) return false;
            if (ReferenceEquals(this, obj)) return true;
            var temp =  obj.Data.Equals(Data) && Equals(obj.Usuario, Usuario) && obj.Codigo == Codigo;

            if (Atributos != null && obj.Atributos != null && Atributos.Count == obj.Atributos.Count)
            {
                for (int i = 0; i < Atributos.Count; i++)
                {
                    temp = Atributos.Contains(obj.Atributos[i]) && temp;
                }
            }
            else
            {
                temp = false;
            }

            return temp;
        }

        public bool MesmoParametros(Busca obj)
        {
            bool temp = true;
            if (Atributos != null && obj.Atributos != null && Atributos.Count == obj.Atributos.Count)
            {
                for (int i = 0; i < Atributos.Count; i++)
                {
                    temp = Atributos.Contains(obj.Atributos[i]) && temp;
                }
            }
            else
            {
                temp = Atributos == null &&  obj.Atributos == null;
            }

            return temp;
        }

        public bool MesmoParametros(Algoritmo obj)
        {
            bool temp = true;
            if (Atributos != null && obj.Atributos != null)
            {
                for (int i = 0; i < Atributos.Count; i++)
                {
                    temp = obj.Atributos.Contains(Atributos[i]) && temp;
                }
            }
            else
            {
                temp = Atributos == null && obj.Atributos == null;
            }

            return temp;
        }

        public override int GetHashCode()
        {
            unchecked
            {
                int result = Data.GetHashCode();
                result = (result*397) ^ (Usuario != null ? Usuario.GetHashCode() : 0);
                result = (result*397) ^ (Atributos != null ? Atributos.GetHashCode() : 0);
                result = (result*397) ^ Codigo.GetHashCode();
                return result;
            }
        }
    }
}
